<template>
  <div ref="goTopBtn" class="go_top" @click="goTop"></div>
</template>

<script>
export default {
  // props: ['timers'],
  data(){
      return{
          timer:'',
      }
  },
  methods: {
    // 返回顶部
    goTop:function(){
        //设置定时器
        this.timer = setInterval(function(){
          //获取滚动条距离顶部高度
          var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
          var ispeed = Math.floor(-scrollTop / 7);
          document.documentElement.scrollTop = document.body.scrollTop = scrollTop+ispeed;
          //到达顶部，清除定时器
          if (scrollTop <= 0) {
            clearInterval(this.timer);
          };
          // this.isTop = true;

        },30);
    },
    clear(){
      if(this.timer){
        clearInterval(this.timer);
      }
    }
  }
}
</script>

<style lang="css">
.go_top{
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 3.75rem;
    height: 5.625rem;
    background-image: url(../../images/go_top.png);
    background-size: 100%;
    z-index: 100;
}
</style>
